From: Florian Müllner Date: Sat, 9 Jun 2018 11:23:35 +0000 (+0200) Subject: events: Re-use event messages where possible X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~929^2~5^2~11 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=e7f2e924100495969d62e91574e03fc0e6fc0112;p=gnome-shell.git events: Re-use event messages where possible Destroying and recreating the entire events list on every change is not only wasteful, it also breaks the clear functionality as messages scheduled for removal are replaced with "new" messages after the first message has been removed. Address both issues by keeping track of all messages and re-use them whenever possible. https://gitlab.gnome.org/GNOME/gnome-shell/issues/325 --- diff --git a/js/ui/calendar.js b/js/ui/calendar.js index a46017ad0..651aac610 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -821,6 +821,8 @@ var EventsSection = new Lang.Class({ this._desktopSettings.connect('changed', this._reloadEvents.bind(this)); this._eventSource = new EmptyEventSource(); + this._messageById = new Map(); + this.parent(); this._title = new St.Button({ style_class: 'events-section-title', @@ -875,20 +877,32 @@ var EventsSection = new Lang.Class({ this._reloading = true; - this._list.destroy_all_children(); - let periodBegin = _getBeginningOfDay(this._date); let periodEnd = _getEndOfDay(this._date); let events = this._eventSource.getEvents(periodBegin, periodEnd); + let ids = events.map(e => e.id); + this._messageById.forEach((message, id) => { + if (ids.includes(id)) + return; + this._messageById.delete(id); + this.removeMessage(message); + }); + for (let i = 0; i < events.length; i++) { let event = events[i]; - let message = new EventMessage(event, this._date); - message.connect('close', () => { - this._ignoreEvent(event); - }); - this.addMessage(message, false); + let message = this._messageById.get(event.id); + if (!message) { + message = new EventMessage(event, this._date); + message.connect('close', () => { + this._ignoreEvent(event); + }); + this._messageById.set(event.id, message); + this.addMessage(message, false); + } else { + this.moveMessage(message, i, false); + } } this._reloading = false;